package cn.jee;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class Utils {
  public static <T> Map<String, String> toMap(T t) {
    Map<String, String> res = new HashMap<>();
    Field[] fields = t.getClass().getDeclaredFields();
    for (Field field : fields) {
      String name = field.getName();
      field.setAccessible(true);
      try {
        String value = "" + field.get(t);
        res.put(name, value);
      } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
      }
    }
    return res;
  }

}
